package com.jeesite.modules.dp.service.user;

import com.jeesite.common.lang.StringUtils;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ExtendUserService {

    @Autowired
    private UserService userService;

    public User getUserByLoginCode(String loginCode) {
        User user = new User();
        user.setLoginCode(loginCode);
        user = userService.getByLoginCode(user);
        return user;
    }

    /**
     * 用户购买VIP后，计算VIP到期日的基准
     *
     * @param user 用户
     * @return
     */
    public Date getUserVipBaseTime(User user) {
        Date expireDate = user.getExtend().getExtendD1();
        Date now = new Date();
        if (expireDate == null) {
            //从未购买过VIP
            return now;
        }
        if (expireDate.before(now)) {
            //已过期,从新购买VIP，那过期基准日从当前时间开始算
            return now;
        }
        return expireDate;
    }
}
